/*
https://leetcode-cn.com/problems/minimum-moves-to-equal-array-elements-ii/solution/zui-shao-yi-dong-ci-shu-shi-shu-zu-yuan-su-xiang-2/
 */
import java.util.Arrays;

public class Solution462 {
    public int minMoves2(int[] nums) {
        Arrays.sort(nums);
        int p=nums.length/2;
        int ans=0;
        for (int num : nums) {
            ans+=Math.abs(num-nums[p]);
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution462().minMoves2(new int[]{1,2,9,10}));
    }
}
